//
// Created by MikeChen on 2025/3/29.
//  while循环


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    int count = 5;
    while (count > 0) {
        printf("你好！\n");
        count--;
//        --count;
//        count = count - 1;
//        count -= 1;
    }

    printf("..........\n");
    count = 5;
    while (count-- > 0) {
        printf("%d,你好！\n", count);
    }

    printf("..........\n");
    count = 5;
    while (--count > 0) {
        printf("%d,你好！\n", count);
    }

    printf("..........\n");
    count = 5;
    do {
        printf("%d,你好！\n", count);
    } while (count-- > 0);

    //案例:计算1到100的和
    printf("..........\n");
    int sum = 0;
    for (int i = 1; i <= 100; ++i) {
        sum += i;
    }
    printf("1~100的和:%d\n", sum);

    printf("..........\n");
    sum = 0;
    int i = 1;
    while (i <= 100) {
        sum += i++;
    }
    printf("1~100的和:%d\n", sum);

    printf("..........\n");
    sum = 0;
    i = 0;
    while (++i <= 100) {
        sum += i;
    }
    printf("1~100的和:%d\n", sum);
    system("read -rsp $'Press enter to continue...\\n'");
    return EXIT_SUCCESS;
}